package com.isoftstone.project.system.uploadfile.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.project.system.uploadfile.domain.Uploadfile;
import com.isoftstone.project.system.uploadfile.service.IUploadfileService;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.domain.PageData;

/**
 * 上传文件Controller
 *
 * @author guoX
 * @date 2020-09-03
 */
@Controller
@RequestMapping("/system/uploadfile")
public class UploadfileController extends BaseController {
    private String prefix = "system/uploadfile";

    @Autowired
    private IUploadfileService uploadfileService;

   // @RequiresPermissions("system:uploadfile:view")
    @GetMapping()
    public String uploadfile() {
        return prefix + "/uploadfile_list";
    }

    /**
     * 查询上传文件列表
     */
   // @RequiresPermissions("system:uploadfile:list")
    @PostMapping("/uploadfilelistPage")
    @ResponseBody
    public Object getuploadfilelistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<Uploadfile> list = uploadfileService.getUploadfilelistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出上传文件列表
     */
    //@RequiresPermissions("system:uploadfile:export")
    @PostMapping("/exportUploadfile")
    @ResponseBody
    public Object exportUploadfile(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<Uploadfile> list = uploadfileService.getUploadfilelistPage(page);
        ExcelUtil<Uploadfile> util = new ExcelUtil<Uploadfile>(Uploadfile. class);
        return util.exportExcel(list, "uploadfile");
    }

    /**
     * 新增上传文件
     */
    @GetMapping("/addUploadfile")
    public String addUploadfile() {
        return prefix + "/uploadfile_add";
    }


    /**
     * 新增保存上传文件
     */
    //@RequiresPermissions("system:uploadfile:add")
    @PostMapping("/addUploadfile")
    @ResponseBody
    public Object insertUploadfile(Uploadfile uploadfile) {
        uploadfileService.insertUploadfile(uploadfile);
        return Tidings.success();

    }

    /**
     * 修改上传文件
     */
    @GetMapping("/toEditUploadfile")
    public String toEditUploadfile(String fileid, ModelMap mmap) {
        Uploadfile uploadfile =uploadfileService.getUploadfileById(fileid);
        mmap.put("uploadfile", uploadfile);
        return prefix + "/uploadfile_edit";
    }

    /**
     * 修改保存上传文件
     */
   // @RequiresPermissions("system:uploadfile:edit")
    @PostMapping("/updateUploadfile")
    @ResponseBody
    public Object updateUploadfile(Uploadfile uploadfile) {
        uploadfileService.updateUploadfile(uploadfile);
        return Tidings.success();
    }

    /**
     * 删除上传文件
     */
    //@RequiresPermissions("system:uploadfile:remove")
    @PostMapping("/deleteUploadfile")
    @ResponseBody
    public Object deleteUploadfile(String fileid) {
        uploadfileService.deleteUploadfileByIds(fileid);
        return Tidings.success();
    }

}
